package cn.uexpo.lhz.biz.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import cn.uexpo.lhz.biz.TestBiz;
import cn.uexpo.lhz.common.oldBase.BOException;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.common.oldUtils.PageUtils;
import cn.uexpo.lhz.dao.TestEntityMapper;
import cn.uexpo.lhz.domain.TestEntity;
import cn.uexpo.lhz.domain.TestEntityExample;

/**
 *
 * @ClassName:  TestBizImpl
 * @Description:TODO(测试接口)
 * 生成接口中方法的快捷键键： 1 Alt+Shift+s  2 Overried/Implement Mathod
 * @author: 李冬建
 * @date:   2020年4月30日 上午10:24:38
 * @Copyright:  1.0.0
 */
@Service
public class TestBizImpl implements TestBiz {

	@Autowired
	private TestEntityMapper testMapper;

	@Override
	public int insert(TestEntity record) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.insert(record);
	}

	@Override
	public int insertSelective(TestEntity record) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.insertSelective(record);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteEntity(TestEntity record) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.deleteByPrimaryKey(record.getId());
	}

	@Override
	public int deleteByIds(List<Integer> ids) throws BOException {
		// TODO Auto-generated method stub
		int no=0;
		if (null!=ids) {
			for (Integer id : ids) {
				no=testMapper.deleteByPrimaryKey(id);
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int delete(List<TestEntity> records) throws BOException {
		// TODO Auto-generated method stub
		int no=0;
		if (null!=records&&records.size()>0){
			for (TestEntity testEntity : records) {
				no=testMapper.deleteByPrimaryKey(testEntity.getId());
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int deleteByExample(TestEntityExample example) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.deleteByExample(example);
	}

	@Override
	public int updateByPrimaryKey(TestEntity record) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.updateByPrimaryKey(record);
	}

	@Override
	public int updateByPrimaryKeySelective(TestEntity record) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByExampleSelective(TestEntity record, TestEntityExample example) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int updateByExample(TestEntity record, TestEntityExample example) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.updateByExample(record, example);
	}

	@Override
	public TestEntity selectByPrimaryKey(Integer id) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.selectByPrimaryKey(id);
	}

	@Override
	public TestEntity selectByUniqueCode(String uniqueCode) throws BOException {
		// TODO Auto-generated method stub
		TestEntity item=null;
		TestEntityExample example=new TestEntityExample();
		TestEntityExample.Criteria citeria=example.createCriteria();
		 citeria.andUniqueCodeEqualTo(uniqueCode);
		 List<TestEntity> items=testMapper.selectByExample(example);
		 if (items!=null&&items.size()>0) {
			 item=items.get(0);
		}
		return item;
	}

	@Override
	public List<TestEntity> selectByExample(TestEntityExample example) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.selectByExample(example);
	}

	@Override
	public long countByExample(TestEntityExample example) throws BOException {
		// TODO Auto-generated method stub
		return testMapper.countByExample(example);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest, TestEntityExample example) throws BOException {
		// TODO Auto-generated method stub
		int pageNum = pageRequest.getPage();
	    int pageSize = pageRequest.getLimit();
	    PageHelper.startPage(pageNum, pageSize);
	    List<TestEntity> records = (List<TestEntity>) testMapper.selectByExample(example);
	    return PageUtils.getPageResult(pageRequest, new PageInfo<TestEntity>(records));
	}

}
